package cn.buk.api.ctrip.dto.share;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;

/**
 * Created by yfdai on 16/1/19.
 */
@XmlAccessorType(XmlAccessType.FIELD)
public class IntlBaseFareInfo {

    @XmlAttribute(name = "ExternalID")
    private String externalId;

    @XmlAttribute(name = "CreateTime")
    private String createTime;

    public String getExternalId() {
        return externalId;
    }

    public void setExternalId(String externalId) {
        this.externalId = externalId;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }


    protected enum ProductType {
        SQ(1, "申请"),
        BJ(2, "包机切位"),
        ZX(3, "直销"),
        QC(4, "清仓产品"),
        TH(6, "特惠");

        private int index;
        private String showName;
        ProductType(int index, String showName) {
            this.index = index;
            this.showName = showName;
        }

        public String value() {
            return name();
        }

        public int getIndex() {
            return index;
        }

        public String getShowName() {
            return showName;
        }

        public static ProductType fromShowName(String v) {
            for (ProductType c: ProductType.values()) {
                if (c.showName.equalsIgnoreCase(v)) {
                    return c;
                }
            }
            return null;
        }
    }


    //去程班期作用点	OutboundDayTimeIndicator	tinyint	单选（0：第一国际段、1：始发航段、2：主航段、3：可为空） 输入0,1,2,3中一个
    protected int getOutboundDayTimeIndicatorVal(String val) {
        if (val.equalsIgnoreCase("第一国际段")) return 0;
        else if (val.equalsIgnoreCase("始发航段")) return 1;
        else if (val.equalsIgnoreCase("主航段")) return 2;
        else return 3;
    }

    //单选（0：普通成人、1：留学生、2：劳工 3：移民、4：海员） 请录入数字
    protected int getEligibilityType(String val) {
        if (val.equalsIgnoreCase("普通成人")) return 0;
        else if (val.equalsIgnoreCase("留学生")) return 1;
        else if (val.equalsIgnoreCase("劳工")) return 2;
        else if (val.equalsIgnoreCase("移民")) return 3;
        else if (val.equalsIgnoreCase("海员")) return 4;
        else return -1;
    }

    protected String parseEligibilityTypes(final String val0) {
        String[] vals = val0.split("[/]");
        String retCode = "";

        for(String val: vals) {
            int status = getEligibilityType(val);

            if (status < 0) continue;

            if (retCode.length() > 0) retCode += "/";

            retCode += Integer.toString(status);
        }

        return retCode;
    }

    //parsePassengerType

    /**
     * 国际公布运价
     * 三种乘客类型:  成人 /成人陪伴儿童/无座婴儿（请录入：0/1/2），可录入多个用/隔开表示或的关系，可以为空默认全部，请输入数字
     * @param val0
     * @return
     */
    protected String parsePassengerTypes(final String val0) {
        String[] vals = val0.split("[/]");
        String retCode = "";

        for(String val: vals) {
            String temp = parsePassengerType(val);

            if (temp.length() == 0) continue;

            if (retCode.length() > 0) retCode += "/";

            retCode += temp;
        }

        return retCode;
    }
    protected String parsePassengerType(final String val) {
        if ("成人".equalsIgnoreCase(val)) return "0";
        else if ("成人陪伴儿童".equalsIgnoreCase(val)) return "1";
        else if ("无座婴儿".equalsIgnoreCase(val)) return "2";
        else return "";
    }

    protected int parseInt(String val) {
        if (val.length() == 0) return 0;

        return Integer.parseInt(val);
    }

    protected int parseOpenJawType(String val) {
        if (val == null) return 0;
        val = val.trim();
        if (val.length() == 0) return 0;

        //单选（0:空，1:双缺、2:单缺、3:始发缺、4:目的地缺）,请输入数字
        if ("双缺".equalsIgnoreCase(val)) return 1;
        if ("单缺".equalsIgnoreCase(val)) return 2;
        if ("始发缺".equalsIgnoreCase(val)) return 3;
        if ("目的地缺".equalsIgnoreCase(val)) return 4;

        return 0;
    }

    protected String parseTripType(String val) {
        if ("单程".equalsIgnoreCase(val)) return "OW";
        else if ("往返".equalsIgnoreCase(val)) return "RT";
//        else if ("单程/往返".equalsIgnoreCase(val)) return "BOTH";
        else return "BOTH";
    }

    protected int parseYesOrNo(String val) {
        if ("不限".equalsIgnoreCase(val)) return 2;
        else
            return val.equalsIgnoreCase("是") ? 1 : 0;
    }

    protected int parseCommissionCalculation(String val) {
        //单选 （1:取严,  2:各取各     请录入1或者2）
        if ("取严".equalsIgnoreCase(val)) return 1;
        else return 2;
    }


}
